home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 738 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.8 KB

  1. From: Russell Gold <goldr@inet.bis.adp.com>
  2. Message-ID: <3149AF56.606E@bis.adp.com>
  3. X-Original-Date: Fri, 15 Mar 1996 12:56:38 -0500
  4. Path: in2.uu.net!bounce-back
  5. Date: 16 Mar 96 09:47:18 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: String value of enum
  9. Organization: Strategic Architecture
  10. References: <4i5sf3$89c@hermes.is.co.za> <Do81tp.H9u@rsvl.unisys.com> <4i80om$2jo@ixnews3.ix.netcom.com>
  11. X-Mailer: Mozilla 2.0 (WinNT; I)
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMUqOLuEDnX0m9pzZAQEQSAF/dcOAlrJyiK/aYQq57oW62NMUbQb+gCyf
  14.     8DUXDOHx+r5frXIUQ1jBwWvBwi8Pv1WQ
  15.     =3fDj
  16.  
  17. Max Welton wrote:
  18. > mtm4@rsvl.unisys.com (Michael McCormick) wrote:
  19. > >"W. Dicks" <wd@isis.co.za> shared the following on 13 Mar 96 07:31:13 GMT:
  20. > >
  21. > >>The system that I'm working often needs to know the string
  22. > >>value of an enum. e.g. enum week{MON=1, ..., SUN} it; it =
  23. > >>TUE;
  24. > >>Then when this enum is passed as a parameter the function
  25. > >>should return the string based on the enum. For instance,
  26. > >>weekImage(it) will return "TUE". Is it not possible that such
  27. > >>a functionality can be built into enums?
  28. > >
  29. > >What you are essentially asking for is language support for converting
  30. > >a label into a string respresentation of its name.  That is a very
  31. > >unusual feature to find in any language, since it would require the
  32. > >compiler to place the symbolic dictionary in the executable file.  I
  33. > >don't think there's a snowball's chance of this getting into C++.
  34. > It's not _that_ unusual. Ada has had this feature starting with
  35. > Ada-83 (the 'image attribute).
  36.  
  37. Very true; however, Ada also gurantees some things about scalar 
  38. values that do not apply to C++ enums:
  39. 1. You can determine the order of a scalar value in its sequence
  40. 2. AFAIK, no two members of the same scalar type can have the same
  41.    underlying representation.
  42.  
  43. As a result, Ada lets you use a scalar type as an array index,
  44. and compute the successor / predecessor from a given value. In
  45. C++, you cannot do this.  For example:
  46.  
  47.   enum Code { ready=0, idle = 0, run, halt };
  48.  
  49.   const char *image( Code value );
  50.  
  51. how would you handle:
  52.    cout << image( (Code) 0 );
  53.  
  54.  
  55. Now if we wanted to guarantee the properties of uniqueness in value 
  56. and sequence in C++, we could do all of these other things, as well. 
  57. -- 
  58. Russell Gold         | (609) 727-2219    
  59. ADP, Inc.            | goldr@bis.adp.com
  60. 201 E. Park Dr.      | russgold@ACM.org                  
  61. Mt. Laurel, NJ 08054 | russgold@aol.com
  62. ---
  63. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  64. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  65. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  66. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  67. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  68.